package br.com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.bean.EngineBean;
import br.com.business.EngineBusiness;

@WebServlet(value="/TesterServlet")
public class TesterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String endpoint = request.getParameter("endpoint");
		String sparql = request.getParameter("sparql");
		
		EngineBusiness engine = new EngineBusiness();
		
		EngineBean<String> bean = engine.executeSelectQuery2(endpoint, sparql);
		if(bean != null) {
			request.setAttribute("result", bean.toString());
		} else {
			request.setAttribute("result", "Erro ao recuperar dados.");
		}
		
		request.setAttribute("endpoint", endpoint);
		request.setAttribute("sparql", sparql);
		
		request.getRequestDispatcher("./tester.jsp").forward(request, response);
	}
}
